from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import redis

# 测试时临时session
def getTempSession():
    # engine = create_engine('postgresql://postgres:nurxat18903@127.0.0.1:5432/iPet')
    # engine = create_engine('postgresql://postgres:nurxat18903@47.108.130.44:5432/iPet')
    engine = create_engine('postgresql://postgres:Change_.&3@172.16.1.82:5432/gd-services')
    # engine = create_engine('oracle+cx_oracle://sde:sdedb@172.10.110.138:1521/dborcl')

    # engine = create_engine(config['pg_uri'])
    # 创建DBSession类型:
    DBSession = sessionmaker(bind=engine)
    """:type:Session"""
    return DBSession()


def excuteQuery(sql):
    session = getTempSession()
    execute = session.execute(sql)
    results = execute.fetchall()
    return results


def getRedisConn():
    redis_pool = redis.ConnectionPool(host='172.16.1.182', port=6379, password='sso123456', db=0)
    return redis.Redis(connection_pool=redis_pool)
